// 商品详情
function product() {
    // mockdata
    //status: 1=正常状态，2=等待开团，3=已开团-未参团，4=已开团-已参团，5=秒杀活动

    let mockData = Mock.mock({
        "lists": {
            'status': 2,
            'statusInfo': {
                'startTime': '10-12 10:00',
                'sellPrice|100-200': 1,
                'originPrice|300-400': 1,
                'joinCount|1000-1200': 1,
                'time|100000-108000': 1
            },
            'imageList|3-8': ["@image('1080x1080',#eac7ce)"],
            'title': "@ctitle(10, 50)",
            'price|100-400.2': 1,
            'priceTag': "@cword(4)",
            'oldPrice|100-400.2': 1,
            'kuaidi|0-10.2': 1,
            'saleNum|100-1000': 1,
            'productAddress': "@city(prefix)",
            'commentNum|100-1000': 1,
            'rate|1-100': 1,
            'commentList|2': [{
                "avatar": "@image('80x80',#fff000)",
                "name": "@cname()",
                "rating|1-5": 1,
                "commentCon": "@csentence(5,100)",
                "imgs|1-10": ["@image('162x162',#5cda47)"],
                "time": "@datetime(yyyy-MM-dd)",
                "color": "@cword(4)",
                "size|30-60": 1,
            }],
            'vendorInfo': {
                "img": "@image('144x144',#977be8)",
                "name": "@ctitle(15, 15)",
                "slogan": "@cword(8)",
                "rating|0-5.2": 1,
                "attention|1-100": 1,
                "productNum|100-9999": 1,
                "vendorAct|1-100": 1,
                "rates1": {
                    "num|7-9.1": 1,
                    "txt": '@cword("高低", 1)',
                    "flag|1-2": true
                },
                "rates2": {
                    "num|7-9.1": 1,
                    "txt": '@cword("高低", 1)',
                    "flag|1-2": true
                },
                "rates3": {
                    "num|7-9.1": 1,
                    "txt": '@cword("高低", 1)',
                    "flag|1-2": true
                }
            },
            'recommendLists|3-6': [{
                'singleLists|6': [{
                    'recoImg': "@image('330x330',#eac7ce)",
                    'title': "@ctitle(10, 30)",
                    'price|100-999.2': 1
                }],

            }],
            'popBoxInfo': {
                "ticket": {
                    "title": "领优惠券",
                    "brief": "快来领取店铺100元优惠券",
                    "list|2-5": [{
                        "money|1-100": 1,
                        "tips": "满100可以用哦",
                        "warn": "限购特种服装",
                        "time": "2017.7.15-2017.7.30"
                    }]
                },

                "jifen": {
                    "title": "积分",
                    "list|2": [{
                        "tag": "积分",
                        "name": "购买可获得88积分",
                        "colorFlag": false
                    }],
                },
                "manzeng": {
                    "title": "满赠",
                    "list": [{
                            "tag": "满赠",
                            "name": "满299元赠送同款衣服一件",
                            "colorFlag": false
                        },

                        {
                            "tag": "满赠",
                            "name": "买套装送奥特曼",
                            "colorFlag": false
                        },
                        {
                            "tag": "限制",
                            "name": "此价格不可以和套装优惠同时享用",
                            "colorFlag": true
                        },
                    ]
                },
                "guarantee": {
                    "title": "基础保障",
                    "list|4": [{
                        "tag": "@ctitle(4)",
                        "name": "@cparagraph()"
                    }]
                },
                "proParams": {
                    "title": "产品参数",
                    "brief": "产品参数",
                    "list|4": [{
                        "tag": "@ctitle(7)",
                        "name": "@cparagraph()"
                    }]
                },
                "selParams": {
                    "brief": "选择颜色分类，尺寸",
                    "params": [{
                            "img": "@image('268x262',#eeefff)",
                            "price|100-500.2": 1,
                            "id": "@id()",
                            "color": "绿色",
                            "sizeList|4-7": [{
                                "size": "@word(2)"
                            }]
                        },
                        {
                            "img": "@image('268x262',#ff4400)",
                            "price|100-500.2": 1,
                            "id": "@id()",
                            "color": "红色",
                            "sizeList|4-7": [{
                                "size": "@word(2)"
                            }]
                        },
                        {
                            "img": "@image('268x262',#9696e2)",
                            "price|100-500.2": 1,
                            "id": "@id()",
                            "color": "粉色",
                            "sizeList|4-7": [{
                                "size": "@word(2)"
                            }]
                        }
                    ]
                },
                "dingzhiParams": {
                    "params": [{
                            "price|100-500.2": 1,
                            "remain|100-9999": 1,
                            "color": "红色",
                            "sizeList|3-6": [{
                                "size": "@word(2)"
                            }]
                        },
                        {
                            "price|100-500.2": 1,
                            "remain|100-9999": 1,
                            "color": "绿色",
                            "sizeList|3-6": [{
                                "size": "@word(2)"
                            }]
                        },
                        {
                            "price|100-500.2": 1,
                            "remain|100-9999": 1,
                            "color": "黑色",
                            "sizeList|2-8": [{
                                "size": "@word(2)"
                            }]
                        }
                    ]
                }
            }


        }
    });
    //   实例化vue
    new Vue({
        el: "#product",
        data() {
            return {
                scrollImages: "", //轮播图
                product: "", //商品的具体信息
                commentList: "", //评论信息list
                commentCount: "", //评价统计
                shopInfo: "", //店铺信息
                shopCoupon: "", //优惠券
                baseService: "", //基础保障
                productParams: "", //产品参数
                producrSizeMainSel: 0, //产品尺寸一级选择  颜色  选的第几个
                producrSizeSecSel: 0, //产品尺寸二级选择  尺寸
                customParam: "", //定制参数
                customMainSel: 0, //定制参数一级选择
                customSecSel: 0, //定制参数二级选择
                buyNum: 1, //购买数量
                status: 1,
                statusInfo: null, //团购|秒杀信息
                day: null, //距结束剩余的天数
                hour: null, //距结束剩余的小时
                minute: null, //距结束剩余的分钟
                second: null, //距结束剩余的秒数

                popBoxInfo: "", //展示信息的弹出框 后台传过来的列表
                popBoxInfoBus: "", //用来存储弹出框按钮点击传过来的参数值
                popBoxInfoFlag: false, //弹框flag  false关闭弹框 true打开弹框
                popBoxInfoType: null, //弹框类型
            }

        },
        methods: {
            // 初始化swiper
            initSwiper: function() {
                let swiper1 = new Swiper('#product_scroll', {
                    pagination: '.swiper-pagination',
                    paginationClickable: true
                });
                let swiper2 = new Swiper('#recommend_scroll', {
                    pagination: '.swiper-pagination',
                    paginationClickable: true
                });

            },
            // 获得当前购物车数量
            getCartCount: function() {
                // 获取当前购物车数量
                let cartCount = sessionStorage.getItem("cartCount");
                if (cartCount) {
                    this.buyNum = cartCount;
                } else {
                    this.buyNum = 1;
                }
            },

            // 基础数据
            getInfo: function() {
                let productUrl = `${urlParam.domain()}api/productInfo/getProduct`;
                axios({
                    url: productUrl,
                    method: "post",
                    params: {
                        token: urlParam.token(),
                        productId: urlParam.productId(),
                        // productId: 120,
                    }
                }).then(res => {
                    //alert(JSON.stringify(res.data.data.product))
                    console.log(res.data.data.product)
                        //  商品轮播图
                    this.scrollImages = res.data.data.carousel;
                    // 商品详细信息
                    this.product = res.data.data.product;
                    //商品状态
                    this.status = res.data.data.product.activityFlag;
                    // 评价信息
                    this.commentList = res.data.data.comment.slice(0, 2); //只展示前两组数据
                    // 评价统计
                    this.commentCount = res.data.data.commentCount;
                }).then(res => {
                    if (this.product.isCustomized == 0) {
                        this.getCustomParams();
                    }
                    this.initSwiper(); //初始化swiper
                })

                this.popBoxInfo = mockData.lists.popBoxInfo;

                this.statusInfo = mockData.lists.statusInfo; //团购|秒杀的信息
            },
            // 店铺优惠券
            getShopCouponList: function() {
                let shopCouponListUrl = `${urlParam.domain()}api/myCoupon/couponList`;
                axios({
                    url: shopCouponListUrl,
                    method: "get",
                    params: {
                        businessId: 1,
                        token: urlParam.token()
                    },
                }).then(res => {
                    this.callPopBoxInfo(0, res.data.data)
                })
            },
            //领取优惠券
            getCoupon: function(couponParams) {
                let shopCouponUrl = `${urlParam.domain()}api/myCoupon/getCoupons`;
                axios({
                    url: shopCouponUrl,
                    method: "post",
                    params: {
                        businessId: 1,
                        couponNo: couponParams.couponNo,
                        couponType: 1, // 0:平台，1：商家
                        startTime: couponParams.startTime,
                        endTime: couponParams.endTime,
                        token: urlParam.token()
                    },
                }).then(res => {
                    alert("领取成功")
                })
            },
            // 基础保障
            getBaseService: function() {
                let bsUrl = `${urlParam.domain()}/api/productInfo/productBasicGuarantee`;
                axios({
                    url: bsUrl,
                    method: "post",
                    params: {
                        productId: urlParam.productId(),
                    },
                }).then(res => {
                    this.baseService = res.data.data;
                })
            },
            // 产品参数
            getProductParams: function() {
                let productParamsUrl = `${urlParam.domain()}api/productInfo/productSpecParameter`;
                axios({
                    url: productParamsUrl,
                    method: "post",
                    params: {
                        token: urlParam.token(),
                        productId: urlParam.productId(),
                        osCategoryId: 38
                    }
                }).then(res => {
                    this.productParams = res.data.data;
                })
            },
            // 获取  产品颜色尺寸
            getProductSize: function() {
                let productSizeUrl = `${urlParam.domain()}api/productInfo/productColorAndSize`;
                axios({
                    url: productSizeUrl,
                    method: "post",
                    params: {
                        token: urlParam.token(),
                        productId: urlParam.productId(),
                    }
                }).then(res => {
                    console.log(res)
                    this.callPopBoxInfo(5, res.data.data)
                        // 设置弹框默认值
                    this.saveSelVal("colorName", this.popBoxInfoBus[this.producrSizeMainSel].colorName)
                        //this.saveSelVal("price", this.popBoxInfoBus[this.producrSizeMainSel].productColorSizeList[0].price)
                    this.saveSelVal("sizeName", this.popBoxInfoBus[this.producrSizeMainSel].productColorSizeList[0].name)
                })
            },
            // 获取店铺信息详情
            getShopInfo: function() {
                let shopUrl = `${urlParam.domain()}api/shop/shopInfo`;
                axios({
                    url: shopUrl,
                    method: "post",
                    params: {
                        id: 1,
                    }
                }).then(res => {
                    this.shopInfo = res.data.data;
                })
            },
            // 获取定制参数
            getCustomParams: function() {
                let cusParUrl = `${urlParam.domain()}api/productInfo/productCustomized`;
                axios({
                    url: cusParUrl,
                    method: "post",
                    params: {
                        token: urlParam.token(),
                        productId: urlParam.productId(),
                    }
                }).then(res => {
                    this.customParam = res.data.data;
                    console.log("定制参数", res)
                }).catch(res => {
                    console.log(111111, res)
                })
            },
            // 调用展示信息弹出框 
            // type：
            // 0：店铺优惠券
            // 1: 积分
            // 2: 正品保障
            // 3: 满赠
            // 4: 产品参数
            // 5: 选择尺寸
            // 6: 开始定制
            callPopBoxInfo: function(type, params) {
                this.popBoxInfoType = type;
                if (params != undefined) {
                    this.popBoxInfoBus = params;
                }
                this.popBoxInfoFlag = true;
                document.documentElement.style.overflow = "hidden";
                document.body.style.overflow = "hidden";
            },
            // 关闭 展示信息弹框
            closeBoxInfo: function() {
                this.popBoxInfoFlag = false;
                document.body.style.overflow = "auto";
                document.documentElement.style.overflow = "auto";
            },
            //  弹框主要参数选择
            selParams: function(index, key, val) {
                this.producrSizeMainSel = index;
                this.producrSizeSecSel = 0;
                this.saveSelVal(key, val);
            },
            // 选择二级参数
            selSecParams: function(index, key, val) {
                this.producrSizeSecSel = index;
                this.saveSelVal(key, val);
                this.saveSelVal("price", this.popBoxInfoBus[this.producrSizeMainSel].productColorSizeList[this.producrSizeSecSel].price)
            },

            // 保存选中的值
            saveSelVal: function(saveKey, saveVal) {
                sessionStorage.setItem(saveKey, saveVal);
            },

            // 添加商品到购物车
            addCart: function() {
                //弹窗为关闭状态
                if (!this.popBoxInfoFlag) {
                    if (this.popBoxInfoBus[this.producrSizeMainSel] == undefined) {
                        this.getProductSize();
                    } else {
                        this.callPopBoxInfo(5);
                    }
                    return;
                }
                //弹窗打开状态,数据不完整
                if (this.buyNum < 1 || sessionStorage.getItem("colorName") == null || sessionStorage.getItem("sizeName") == null) {
                    return;
                }
                //调用加入购物车接口
                let url = `${urlParam.domain()}api/shoppingCart/add`;
                // 获取购物车数量
                this.getCartCount();
                var buyObj = {
                    token: urlParam.appToken,
                    buyNumber: this.buyNum,
                    colorName: sessionStorage.getItem("colorName"),
                    customValues: null,
                    name: this.product.name,
                    picImg: this.popBoxInfoBus[this.producrSizeMainSel].colorCoverPic,
                    productNumber: this.product.productNumber,
                    productPrice: this.product.showPrice,
                    sizeName: sessionStorage.getItem("sizeName"),
                    sellerId: this.product.userId,
                }
                alert('buyObj=' + JSON.stringify(buyObj))
                axios({
                    url: url,
                    method: 'post',
                    params: buyObj,
                }).then(res => {
                    if (res.data.code == 1) {
                        alert("加入购物车成功！")
                    } else {
                        alert("加入购物车失败！")
                    }
                })
            },
            //立即购买  这边直接执行跳转方法，调用原生方法
            buyNow: function() {
                //弹窗为关闭状态
                if (!this.popBoxInfoFlag) {
                    if (this.popBoxInfoBus[this.producrSizeMainSel] == undefined) {
                        this.getProductSize();
                    } else {
                        this.callPopBoxInfo(5);
                    }
                    return;
                }
                //弹窗打开状态,数据不完整
                if (this.buyNum < 1 || sessionStorage.getItem("colorName") == null || sessionStorage.getItem("sizeName") == null) {
                    return;
                }

                //调用原生立即购买
                var postObj = {
                    "addressId": "",
                    "couponId": "",
                    "payAmount": this.product.showPrice * this.buyNum,
                    "buyNumber": this.buyNum,
                    "orderList": [{
                        "shopName": this.shopInfo.shopName,
                        "buyNumber": this.buyNum,
                        "couponId": '',
                        "groupPurchaseActivityId": '',
                        "groupPurchaseId": '',
                        "invoiceType": '',
                        "orderInvoice": {
                            "email": '',
                            "invoiceTitle": '',
                            "taxpayerNumber": '',
                            "telephone": '',
                        },
                        "orderProducts": [{
                            "buyNumber": this.buyNum,
                            "colorName": sessionStorage.getItem("colorName"),
                            "customValues": null,
                            "name": this.product.name,
                            "picImg": this.popBoxInfoBus[this.producrSizeMainSel].colorCoverPic,
                            "price": this.product.showPrice,
                            "productNumber": this.product.productNumber,
                            "productPrice": this.product.showPrice,
                            "sizeName": sessionStorage.getItem("sizeName"),
                            "spikeId": '',
                        }],
                        "sellerId": this.product.userId,
                        "payAmount": this.product.showPrice * this.buyNum,
                        "shipmentAmount": this.product.monthlySales,
                    }],
                };
                alert(JSON.stringify(postObj))
                if (browser.versions.ios || browser.versions.iPhone || browser.versions.iPad) {
                    window.webkit.messageHandlers.purchaseNowPush.postMessage(postObj);
                }
                if (browser.versions.android) {
                    window.AndroidWebView.purchaseNowPush(JSON.stringify(postObj))
                }
            },
            //将剩余秒数转换为天 时 分 秒格式
            exchangeTimeLeave: function() {
                var time = this.statusInfo.time;
                this.second = time % 60;
                this.minute = parseInt(time / 60 % 60);
                this.hour = parseInt(time / 3600 % 24);
                this.day = parseInt(time / 86400);
            },
            //倒计时
            countdown: function() {
                var that = this;
                setInterval(function() {
                    that.statusInfo.time--;
                    that.exchangeTimeLeave();
                }, 1000)
            }
        },
        components: {
            counter,
        },
        filters: {
            // 时间格式化
            format: function(dateTime) {
                var unixTimestamp = new Date(dateTime);
                var y = unixTimestamp.getFullYear();
                var m = unixTimestamp.getMonth() + 1;
                var d = unixTimestamp.getDate();
                var h = unixTimestamp.getHours();
                var min = unixTimestamp.getMinutes();
                if (m < 10) {
                    m = "0" + m;
                }
                if (d < 10) {
                    d = "0" + d;
                }
                if (h < 10) {
                    h = "0" + h;
                }
                if (min < 10) {
                    min = "0" + min;
                }
                var time = y + "-" + m + "-" + d;
                return time;
            },
            //好评度计算
            starRating: function(good, total) {
                return (good / total).toFixed(2) * 100
            },
            //基础保障
            baseService: function(val) {
                switch (val) {
                    case "0":
                        return "正品保证";
                        break;
                    case "1":
                        return "急速退款";
                        break;
                    case "2":
                        return "七天无理由退货";
                        break;
                }
            },
        },

        watch: {
            // 监听选择产品分类尺寸 默认选择
            "producrSizeMainSel": function() {
                this.saveSelVal("sizeName", this.popBoxInfoBus[this.producrSizeMainSel].productColorSizeList[0].name);
                this.saveSelVal("price", this.popBoxInfoBus[this.producrSizeMainSel].productColorSizeList[0].price);
            }
        },
        created() {
            urlParam.getAndroidToken();
            this.getInfo();
            this.getCartCount();
            this.getBaseService();
            this.getProductParams();
            this.getShopInfo();
            this.exchangeTimeLeave();
            this.countdown();
        },
        beforeUpdate() {
            fastClick();
        }
    })
}
//商品详情介绍
function productInfo() {
    new Vue({
        el: "#productInfo",
        data() {
            return {
                navGuide: [
                    { "name": "商品介绍" },
                    { "name": "规格参数" },
                    { "name": "包装售后" },
                ],
                cur: 0, //默认激活tab选项第一项
                productImgs: null, //后台传入的商品详情图片
                productParams: null, //后台传入的商品规格参数
                productService: "", // 商品售后
                productId: "" //商品id
            }
        },
        methods: {
            // 获得页面信息
            getInfo: function(pageType = 0) {
                // 根据传入的不同的pagetype 来请求不同的页面接口
                // 0:商品介绍 1:规格参数 2:包装售后
                if (pageType == 0) {
                    var infoUrl = `${urlParam.domain()}api/productInfo/productIntroduction`;
                } else if (pageType == 1) {
                    var infoUrl = `${urlParam.domain()}api/productInfo/productSpecParameter`;
                } else {
                    var infoUrl = `${urlParam.domain()}api/productInfo/productIntroduction`;
                }
                axios({
                    url: infoUrl,
                    method: "post",
                    params: {
                        token: urlParam.token(),
                        productId: urlParam.productId(),
                        osCategoryId: 38
                    }
                }).then(res => {
                    this.productId = urlParam.productId();
                    if (pageType == 0) {
                        this.productImgs = res.data.data.desciption.replace(res.data.data.desciption ? /&(?!#?\w+;)/g : /&/g, '&amp;')
                            .replace(/&lt;/g, "<")
                            .replace(/&gt;/g, ">")
                            .replace(/&nbsp;/g, "\ ")
                            .replace(/&quot;/g, "\'")
                            .replace(/&#39;/g, "\'");

                    } else if (pageType == 1) {
                        this.productParams = res.data.data;
                    } else {
                        return this.productService = null;
                    }

                })
            },
            // 切换tab
            tab: function(index) {
                this.cur = index;
                this.getInfo(index);
            }
        },

        created() {
            this.getInfo();
        },
        beforeUpdate() {
            fastClick();
        }
    })
}
//商品评价
function productComment() {
    // mockdata
    let mockData = Mock.mock({
        "lists": {
            'filter': {
                "rating|70-100": 1,
                "filterItem": [{
                        "name": "全部",
                        "count|1-999": 1,
                    },
                    {
                        "name": "好评",
                        "count|1-999": 1,
                    },
                    {
                        "name": "中评",
                        "count|1-999": 1,
                    },
                    {
                        "name": "差评",
                        "count|1-999": 1,
                    },
                    {
                        "name": "有图",
                        "count|1-999": 1,
                    },
                ]
            },
            'commentList|3-5': [{
                "avatar": "@image('80x80',#fff000)",
                "name": "@cname()",
                "rating|1-5": 1,
                "commentCon": "@csentence(5,100)",
                "imgs|1-5": ["@image('162x162',#5cda47)"],
                "time": "@datetime(yyyy-MM-dd)",
                "color": "@cword(4)",
                "size|30-60": 1,
                "reply": "@csentence(5,100)"
            }],
        }
    });
    // 实例化vue
    new Vue({
        el: "#productComment",
        data() {
            return {
                filter: "", //商品评价筛选
                filterCur: 0, //设置筛选默认选中
                commentList: "", // 评论 信息
                praiseOf: "", //好评度
                productId: urlParam.productId(), //产品id
            }
        },
        methods: {
            // 获得页面信息
            getInfo: function() {
                let commentUrl = `${urlParam.domain()}api/productInfo/productComment`;
                axios({
                    url: commentUrl,
                    method: "post",
                    params: {
                        token: urlParam.token(),
                        productId: this.productId,
                        type: 4,
                        pages: 0
                    }
                }).then(res => {
                    console.log(res)
                    this.filter = res.data.data.count;
                    this.commentList = res.data.data.commentList;
                    this.praiseOf = res.data.data.praiseOf;
                })


            },
            // 筛选sel
            sel: function(index) {
                this.filterCur = index;
                let filterUrl = `${urlParam.domain()}api/productInfo/productComment`;
                // 修改传入的type
                let type;
                switch (index) {
                    case 0:
                        type = 4
                        break;
                    case 1:
                        type = 2
                        break;
                    case 2:
                        type = 1
                        break;
                    case 3:
                        type = 0
                        break;
                    case 4:
                        type = 3
                        break;
                }
                axios({
                    url: filterUrl,
                    method: "post",
                    params: {
                        token: urlParam.token(),
                        productId: this.productId,
                        type,
                        pages: 0
                    }
                }).then(res => {
                    this.commentList = res.data.data.commentList;
                })
            },
            // 只看当前产品
            checkCurProduct: function() {
                alert(1)
            }
        },
        filters: {
            // 时间格式化
            format: function(dateTime) {
                var unixTimestamp = new Date(dateTime);
                var y = unixTimestamp.getFullYear();
                var m = unixTimestamp.getMonth() + 1;
                var d = unixTimestamp.getDate();
                var h = unixTimestamp.getHours();
                var min = unixTimestamp.getMinutes();
                if (m < 10) {
                    m = "0" + m;
                }
                if (d < 10) {
                    d = "0" + d;
                }
                if (h < 10) {
                    h = "0" + h;
                }
                if (min < 10) {
                    min = "0" + min;
                }
                var time = y + "-" + m + "-" + d;
                return time;
            },
        },
        created() {
            this.getInfo();
        },
        mounted() {

        },
        watch: {

        },
        beforeUpdate() {
            fastClick();
        }
    })
}


// 商品分类
function productCategory() {
    let mockData = Mock.mock({
        "lists": {
            "singleList|2": ["@cword(4)"],
            "moreList": {
                "more": {
                    "title": "@cword(4)",
                    "conList|6": ["@cword(5)"],
                },
                "simple|8": ["@cword(4)"]
            }
        }
    });
    new Vue({
        el: "#productCategory",
        data() {
            return {
                singleList: null,
                moreList: null,
            }
        },
        methods: {
            // 获得页面信息
            getInfo: function() {
                this.singleList = mockData.lists.singleList;
                this.moreList = mockData.lists.moreList;
                let url = `${urlParam.domain()}api/shop/getShopCommodityCategory`
                axios({
                    method: "post",
                    url: url,
                    params: {
                        token: urlParam.token,
                        id: 1
                    }
                }).then(function(res) {
                    console.log(res.data.data)
                }).catch(function(error) {
                    console.log(error);
                });

            },

        },
        created() {
            this.getInfo();
        },
        beforeUpdate() {
            fastClick();
        }
    })
}

// 商品列表
// function productList() {
//   // mockdata
//   let mockData = Mock.mock({
//     "shop_name": "@ctitle(5, 13)",
//     "pro_list|4-8": [{
//       'img': "@image('498x498',#eac7ce)",
//       'title': "@ctitle(5, 10)",
//       'sellprice|100-200.2': 239.00,
//       'sellcount|800-1000': 800
//     }]
//   });
//   //   实例化vue
//   new Vue({
//     el: "#productList",
//     data() {
//       return {
//         type_num: null, //当前页面type对应的tag
//         pro_list: null, //产品列表
//         showTuijian: false,
//         tuijian_type: 1,
//         shaixuan_type: 1
//       }
//     },
//     methods: {
//       // 获取商品列表
//       getProList: function() {



//         this.pro_list = mockData.pro_list;
//       },
//       toggleTuijian: function() {
//         this.showTuijian = !this.showTuijian;
//       },
//       changeTuijianType: function(n) {
//         this.tuijian_type = n;
//         this.shaixuan_type = 1;
//         this.showTuijian = !this.showTuijian;
//       },
//       changeShaixuanType: function(n) {
//         this.shaixuan_type = n;
//       }
//     },
//     created() {
//       this.getProList();
//     },
//     beforeUpdate() {
//       fastClick();
//     }
//   })
// }



// 商品列表
function productList() {
    // mockdata
    let mockData = Mock.mock({
        "shop_name": "@ctitle(5, 13)",
        "pro_list|10": [{
            'img': "@image('536x684',#eac7ce)",
            'title': "@ctitle(5, 10)",
            'sellprice|100-200.2': 239.00,
            'sellcount|800-1000': 800
        }],
        'popBoxInfo': {
            "productFilter": {
                "params": [{
                        "price|100-500.2": 1,
                        "id": "@id()",
                        "brand": "香奈儿（xiangnaier）",
                        "sizeList|10-15": [{
                            "size": "@word(2)"
                        }],
                        "popBoxInfoToggle": true, //弹框toggle
                    },
                    {
                        "price|100-500.2": 1,
                        "id": "@id()",
                        "brand": "guchi",
                        "sizeList|4-7": [{
                            "size": "@word(2)"
                        }],
                        "popBoxInfoToggle": false, //弹框toggle
                    },
                    {
                        "price|100-500.2": 1,
                        "id": "@id()",
                        "brand": "bithc",
                        "sizeList|4-7": [{
                            "size": "@word(2)"
                        }],
                        "popBoxInfoToggle": false, //弹框toggle
                    },
                    {
                        "price|100-500.2": 1,
                        "id": "@id()",
                        "brand": "bithc",
                        "sizeList|4-7": [{
                            "size": "@word(2)"
                        }],
                        "popBoxInfoToggle": false, //弹框toggle
                    },
                    {
                        "price|100-500.2": 1,
                        "id": "@id()",
                        "brand": "bithc",
                        "sizeList|4-7": [{
                            "size": "@word(2)"
                        }],
                        "popBoxInfoToggle": false, //弹框toggle
                    }
                ]
            },

        }
    });
    //   实例化vue
    new Vue({
        el: "#productList",
        data() {
            return {
                pro_list: [], //产品列表
                popBoxInfoType: null, //弹框类型
                popBoxInfoParmasType: null, //弹框中默认选中参数
                popBoxInfoParmasCur: 0, //弹框选项默认 0
                popBoxInfoFlag: false, //弹框flag  false关闭弹框 true打开弹框
                popBoxInfoBus: null,

            }
        },
        methods: {
            // 获得商品列表
            getProList: function() {
                let proListUrl = `${urlParam.domain()}api/productInfo/productSearch`;
                axios({
                    url: proListUrl,
                    method: "post",
                    params: {
                        token: urlParam.token(),
                        brandId: "",
                        keyword: "",
                        pages: 0,
                        sortId: urlParam.sortId()
                    }
                }).then(res => {
                    console.log("商品列表", res)
                    this.pro_list = res.data.data;
                }).catch(err => {
                    console.log(err)
                })
                this.popBoxInfo = mockData.popBoxInfo;
            },
            callPopBoxInfo: function(type, params) {
                this.popBoxInfoType = type;
                this.popBoxInfoBus = (params);
                this.popBoxInfoFlag = true;
                document.documentElement.style.overflow = "hidden";
                document.body.style.overflow = "hidden";
            },
            // 关闭 展示信息弹框
            closeBoxInfo: function() {
                this.popBoxInfoFlag = false;
                document.body.style.overflow = "auto";
                document.documentElement.style.overflow = "auto";
            },
            //  弹框主要参数选择
            selParams: function(val) {
                this.popBoxInfoParmasType = val;
                this.popBoxInfoParmasCur = val;
            },
            toggleItem: function() {
                this.popBoxInfoBus.popBoxInfoToggle = !this.popBoxInfoBus.popBoxInfoToggle;
            },

        },
        created() {
            this.getProList();
        },
        beforeUpdate() {
            fastClick();
        },
    })
}